package com.dq.domain.goods;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.org.Org;
import com.dq.domain.sys.section.SysSection;
import com.dq.domain.sys.user.user.base.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.util.Collection;
import java.util.List;

/**
 * 购物车
 */
@Data
@Entity
@ApiModel("购物车")
public class ShoppingCart extends BaseEntity {

    @ManyToOne
    @ApiModelProperty("用户")
    protected SysUser user;

    @ManyToOne
    @ApiModelProperty("机构")
    protected SysSection org;

    public Vo toVo(List<ShoppingBag> bags) {
        Vo vo = new Vo();
        vo.user = null == this.user ? null : this.user.toVO(false);
        vo.bags = (Collection<ShoppingBag.Vo>) VO.toVOCollection(bags);
        vo.orgVo = null == org ? null : (Org.Vo) this.org.toVO(false);
        return vo;
    }

    @Data
    @ApiModel("购物车视图")
    public static class Vo implements VO {
        @ApiModelProperty("用户")
        private VO user;
        @ApiModelProperty("机构")
        private Org.Vo orgVo;
        @ApiModelProperty("购物袋产品")
        private Collection<ShoppingBag.Vo> bags;
    }
}
